/* Author: Panos Sakkos 2011 
 * Email: p.sakkos@di.uoa.gr
 */

#include "vector.h"
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

Vector::Vector(int size)
{
	this->size = size;
	values = new double[size];

	for(int i = 0; i < size; i++)
	{
		values[i] = 0;	
	}
}

Vector::Vector(const Vector &vector)
{
	this->size = vector.size;
	
	values = new double[size];

	for(int i = 0; i < size; i++)
	{
		values[i] = vector.values[i];	
	}	
}


double Vector::GetValue(int i)
{
	return values[i];
}

void Vector::SetValue(int i, double value)
{
	this->values[i] = value;
}

void Vector::ReadInput(void)
{
	double input;
	
	for(int i = 0; i < this->size; i++)
	{
//		cout << "Please, type value " << i << " for vector: ";
		
		cin >> input;
		this->values[i] = input;	
	}
}

Vector Vector::operator-(Vector vector)
{
	Vector result(this->size);
	
	for(int i = 0; i < this->size; i++)
	{
		result.SetValue(i, this->values[i] - vector.values[i]);
	}
	
	return result;
}

double Vector::GetInfinityNorm()
{
	double max = fabs(this->values[0]);	
	
	for(int i = 1; i < this->size; i++)
	{
		if(fabs(values[i]) > max)
		{
			max = fabs(values[i]);			
		}
	}
	
	return max;
}

void Vector::Print(void)
{
	for(int i = 0; i < this->size; i++)
	{
		cout << setfill (' ') << setw (9) << values[i]; cout << " ";
	}
}

Vector Vector::operator= (const Vector &vector)
{
	if(this == &vector)
	{
		return *this;	
	}
	
	delete values;
	
	size = vector.size;
	values = new double[vector.size];
	
	for(int i = 0; i < size; i++)
	{
		values[i] = vector.values[i];	
	}
	
	return *this;
}
